import { defineStore } from 'pinia'
import { ref } from 'vue'
/**
 * 用户store：存储登录用户相关数据
 */

export const useUserStore = defineStore(
  'gh-user',
  () => {
    //全局变量：登录用户
    const user = ref({
      userData: '',
      token: ''
    })
    //存储用户信息
    const setUser = (userData, token) => {
      user.value.userData = userData
      user.value.token = token
    }
    //删除用户信息
    const delUser = () => {
      user.value = {}
    }

    return { user, setUser, delUser }
  },
  { persist: true } //开启数据持久化
)
